<ui:composition template="index.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

	<ui:define name="content">
		<h3 id="title-doc">
			<a href="" data-reveal-id="dlg-new" class="icon-plus"></a> |
			Administradores
		</h3>

		<p:dataTable id="dataTable" var="admin"
			value="#{administratorBean.administrators}" paginator="true"
			rows="25"
			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
			rowsPerPageTemplate="25, 50, 75, 100">

			<p:column>
				<f:facet name="header">
					<h:outputText value="Nome" />
				</f:facet>
				<h:outputText value="#{admin.firstName} #{admin.lastName}" />
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="Usuário" />
				</f:facet>
				<h:outputText value="#{admin.username}" />
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="Email" />
				</f:facet>
				<h:outputText value="#{admin.email}" />
			</p:column>

			<p:column>
				<f:facet name="header">
					<h:outputText value="Ações" />
				</f:facet>
				<span data-reveal-id="dlg-update"> <p:commandButton
						actionListener="#{administratorBean.select}"
						update="@(#form-update)" value="Alterar" process="dataTable" />
				</span>
				<p:commandButton action="#{administratorBean.delete}"
					actionListener="#{administratorBean.select}" value="Excluir"
					update="dataTable" process="dataTable" />
			</p:column>
		</p:dataTable>
	</ui:define>

	<!-- Dialogs -->
	<ui:define name="dialogs">
		<div id="dlg-new" class="reveal-modal medium">
			<a class="close-reveal-modal">&#215;</a>
			<h3>Adicionar Administrador</h3>

			<h:form id="form-new">
				<p:messages id="msg-new" autoUpdate="true" closable="true"
					showDetail="false" />

				<h:outputText for="new-firstName" value="Nome" />
				<p:inputText id="new-firstName"
					value="#{administratorBean.administrator.firstName}"
					required="true" validator="validaAlfaNumerico"
					requiredMessage="Favor informar o nome!" />

				<h:outputText for="new-lastName" value="Sobrenome" />
				<p:inputText id="new-lastName"
					value="#{administratorBean.administrator.lastName}" required="true"
					validator="validaAlfaNumerico"
					requiredMessage="Favor informar o sobrenome!" />

				<h:outputText for="new-username" value="Usuário" />
				<p:inputText id="new-username"
					value="#{administratorBean.administrator.username}" required="true"
					validator="validaAlfaNumerico"
					requiredMessage="Favor informar o Usuário!" />

				<h:outputText for="new-email" value="Email" />
				<p:inputText id="new-email"
					value="#{administratorBean.administrator.email}" required="true"
					validator="validaEmail" requiredMessage="Favor informar o email" />

				<h:outputText for="new-password" value="Senha" />
				<p:password id="new-password"
					value="#{administratorBean.administrator.password}" required="true"
					feedback="true" match="new-confirmPassword" />

				<h:outputText for="new-confirmPassword" value="Confirmar Senha" />
				<p:password id="new-confirmPassword" value="" required="true" />

				<p:commandButton actionListener="#{administratorBean.save}"
					oncomplete="validateForm(xhr, status, args, 'dlg-new')"
					value="Salvar" update="form-new" process="form-new" />
				<p:button value="Cancelar" />
			</h:form>
		</div>

		<div id="dlg-update" class="reveal-modal medium">
			<a class="close-reveal-modal">&#215;</a>
			<h3>Alterar Administrador</h3>

			<h:form id="form-update">
				<p:messages id="msg-update" autoUpdate="true" closable="true"
					showDetail="false" />

				<h:outputText for="update-firstName" value="Nome" />
				<p:inputText id="update-firstName"
					value="#{administratorBean.administrator.firstName}"
					required="true" validator="validaAlfaNumerico"
					requiredMessage="Favor informar o nome!" />

				<h:outputText for="update-lastName" value="Sobrenome" />
				<p:inputText id="update-lastName"
					value="#{administratorBean.administrator.lastName}" required="true"
					validator="validaAlfaNumerico"
					requiredMessage="Favor informar o sobrenome!" />

				<h:outputText for="update-username" value="Usuário" />
				<p:inputText id="update-username"
					value="#{administratorBean.administrator.username}" required="true"
					validator="validaAlfaNumerico"
					requiredMessage="Favor informar o Usuário!" />

				<h:outputText for="update-email" value="Email" />
				<p:inputText id="update-email"
					value="#{administratorBean.administrator.email}" required="true"
					validator="validaEmail" requiredMessage="Favor informar o email" />

				<h:outputText for="update-password" value="Senha" />
				<p:password id="update-password"
					value="#{administratorBean.administrator.password}" required="true"
					feedback="true" match="update-confirmPassword" />

				<h:outputText for="update-confirmPassword" value="Confirmar Senha" />
				<p:password id="update-confirmPassword" value="" required="true" />

				<p:commandButton actionListener="#{administratorBean.update}"
					oncomplete="validateForm(xhr, status, args, 'dlg-update')"
					value="Salvar" update="form-update" process="form-update" />
				<p:button value="Cancelar" />
			</h:form>
		</div>
	</ui:define>

</ui:composition>